# coding:utf8
# 为元组元素命名，提高程序的可读性

# 程序中充斥这个各个索引值，可读性不高
student = ('shisongyan', '18', 'male')
print (student[0])

# 方法一:定义变量
NAME, AGE, SEX = range(3)
print (student[NAME])


# 方法二:使用标准库中的namedtuple代替内置的tuple
from collections import namedtuple
Student = namedtuple('Student', ['name', 'age', 'sex'])
s = Student('shisongyan', '18', 'male')
print (s.name)